<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/20/020
 * Time: 11:19
 */

namespace app\admin\controller;
use app\api\model\Brand as BrandModel;
use app\api\validate\BrandValidate;


class Brand extends Common {
    /**
     * 品牌列表
     * @return \think\response\View
     */
    public function index() {
        $data = BrandModel::all();
        $this->assign('data', $data);
        return view();
    }

    /**
     * 创建或者编辑品牌
     * @return \think\response\Json|\think\response\View
     */
    public function save_brand() {
        $id = input('param.id', 0);
        if (request()->isAjax()) {
            $brand_validate = new BrandValidate();
            $brand_validate->goCheck();
            $param = $brand_validate->getDataByRule(input('param.'));
            $data = BrandModel::createOrUpdateBrand($param, $id);
            return json($data);
        } else {
            $data = [];
            if ($id > 0) {
                $data = BrandModel::get($id);
            }
            $this->assign('data', $data);
            return view();
        }
    }
}